package com.mind.login.model;

import com.mind.core.net.model.Connector;
import com.mind.core.server.DataHelper;
import com.mind.core.util.Guid;
import com.mind.quest.model.PlayerQuest;

public class Player extends Connector{
	private String charId;
	private String net;
	public PlayerProperty property;
	public PlayerQuest quest;
	public PlayerBattleProperty battleProperty;
	public boolean isNew=false;
	public Player(){};
	public void load(String charId,String net){
		this.id=Guid.createGuid(charId, net);
		Player tmp=(Player) DataHelper.getInstance().getCachePlayer(id);
		if(tmp!=null){
			this.property=tmp.property;
			this.quest=tmp.quest;
		}else{
			PlayerProperty _playerProperty=(PlayerProperty) find(PlayerProperty.class, id);
			if(_playerProperty==null){
				_playerProperty=new PlayerProperty();
				_playerProperty.setCharId(charId);
				_playerProperty.setNet(net);
				_playerProperty.setId(this.id);
				_playerProperty.insert();
				isNew=true;
			}
			this.property=_playerProperty;
			PlayerQuest _playerQuest=(PlayerQuest)find(PlayerQuest.class, id);
			if(_playerQuest==null){
				_playerQuest=new PlayerQuest();
				_playerQuest.setId(this.id);
				_playerQuest.insert();
			}
			this.quest=_playerQuest;
			 DataHelper.getInstance().addCachePlayer(this);
		}
		this.update();
	}
	public void update(){
		property.update();
		quest.update();
	}
	public String getCharId() {
		return charId;
	}
	public void setCharId(String charId) {
		this.charId = charId;
	}
	public String getNet() {
		return net;
	}
	public void setNet(String net) {
		this.net = net;
	}
}
